import Cookies from 'js-cookie'

export function setCookie(name, value, domain, secure) {
  const day = 30 // cookie过期天数为30天
  let str = ''
  if (window.location.host === 'localhost:8880') str = domain
  else if (window.location.host === 'www.rcepdev.com:8880')
    str = '.rcepdev.com' // 兼容测试环境
  else if (window.location.host === '192.168.1.9:8880')
    str = '192.168.1.9' // 兼容测试环境
  else {
    const host = window.location.host
    const arr = host.split('.')
    str = '.' + arr[arr.length - 2] + '.' + arr[arr.length - 1]
  }
  const myName = name
  const myValue = value
  console.log(myName, str)
  Cookies.set(myName, myValue, {
    expires: day,
    path: '/',
    domain: str,
    // HttpOnly: true,
    secure: secure ? secure : false,
    // sameSite: 'strict'
  })
}
